fix(a2a): respect auto_create_session flag in A2A executor session preparation#5351
fix(a2a): respect auto_create_session flag in A2A executor session preparation#5351nickchecan wants to merge 20 commits intogoogle:mainfrom
Conversation
|
Fixed pipeline failures: applied pyink formatting, updated test assertions to expect auto_create_session=True, and resolved mypy errors (return type annotations, dict[str, Any], AbstractAsyncContextManager, and asyncio.Task[None]). |
|
@rohityan Hi! The pipeline failures have been fixed. The pyink formatting, test assertions updated to expect |
|
Hi @nickchecan , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Your PR has been received by the team and is currently under review. We will provide feedback as soon as we have an update to share. |
|
Hi @DeanChensj , can you please review this. |
|
@nickchecan this would represent a breaking change for all the users who are not relying on the |
Problem:
When a
Runneris configured withauto_create_session=False, the A2A executorlayer completely bypasses this flag. Both
A2aAgentExecutor._prepare_session(legacy executor) and
_A2aAgentExecutor._resolve_session(new executor impl)call
runner.session_service.get_session()andrunner.session_service.create_session()directly, instead of going through
runner._get_or_create_session()(the methodthat actually checks the
auto_create_sessionflag). As a result, sessions arealways silently auto-created regardless of the flag value, making it impossible
to enforce explicit session management in A2A workflows.
Additionally,
to_a2a()'s internally createdRunnerdid not setauto_create_session=True, which would cause every incoming A2A request to failwith
SessionNotFoundErrorsince A2A clients never pre-create sessions.Solution:
session_servicecalls in_prepare_sessionand_resolve_sessionwithrunner._get_or_create_session(). This single methodalready encapsulates the
auto_create_sessionlogic and raisesSessionNotFoundErrorwhen the flag isFalseand the session is missing.auto_create_session=Trueinto_a2a()'s internalcreate_runner, topreserve backward-compatible behavior for users who rely on
to_a2a()to handlesession lifecycle automatically.
Testing Plan
Unit Tests:
Updated tests in
test_a2a_agent_executor.pyandtest_a2a_agent_executor_impl.pyto mock
runner._get_or_create_sessioninstead ofrunner.session_service.get_session/
create_session. Rewrotetest_resolve_session_creates_new_sessionto verifythe correct method and arguments are used.
Fixed
tests/unittests/a2a/integration/server.pyto passauto_create_session=Trueto
FakeRunner, restoring the pre-fix behavior for integration tests where sessionsare always created on-the-fly.
pytest tests/unittests/a2a/ -v
...
56 passed, 139 warnings
pytest tests/unittests/ -v
...
5456 passed, 1 skipped, 2240 warnings in 130.24s
Manual End-to-End (E2E) Tests:
Created a minimal A2A server using
to_a2a()with a LiteLLM-backed agent andtested three scenarios:
Scenario 1 —
auto_create_session=True(default viato_a2a):{ "result": { "status": { "state": "completed" }, "artifacts": [ { "parts": [{ "kind": "text", "text": "It's currently 2026-04-15 22:51:30 UTC." }] } ] } }Scenario 2 —
auto_create_session=Falsewith missing session:{ "result": { "status": { "state": "failed", "message": { "parts": [{ "kind": "text", "text": "Session not found: <session_id>" }] } } } }Scenario 3 —
auto_create_session=Falsewith pre-created session:Session pre-created via
lifespanhook → request succeeds withstate: completed.Checklist
Additional context
The
runner._get_or_create_session()method already existed and was usedcorrectly by all other runner entry points (
run_async,run_live,rewind_async). The A2A executor was the only layer that bypassed it, makingauto_create_sessionunreliable in A2A-based deployment.